package com.sub.kafka.producer.partitioner;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @ClassName SubPartitioner
 * @Description: 自定义消息分区器
 * 1、实现Partitioner接口
 * 2、重写抽象方法
 *
 * @Author Submerge.
 * @Since 2025/6/1 21:11
 * @Version 1.0
 */
public class SubPartitioner implements Partitioner {


    /**
     * 分区计算规则
     * @param topic The topic name
     * @param key The key to partition on (or null if no key)
     * @param keyBytes The serialized key to partition on( or null if no key)
     * @param value The value to partition on or null
     * @param valueBytes The serialized value to partition on or null
     * @param cluster The current cluster metadata
     * @return
     */
    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        //TODO 当前为单节点只支持单分区，所以直接返回0
        return 0;
    }

    @Override
    public void close() {

    }

    @Override
    public void configure(Map<String, ?> configs) {

    }
}
